#!/usr/bin/env python
import urllib
import sys,os,re


#path="./data/"
path="./"
url="archive.routeviews.org/route-views.isc/bgpdata/"
f=urllib.urlopen("http://"+url)
ff=f.read()
f.close()
mlist=re.findall('alt=\"\[DIR\]\"></td><td><a href=\"([0-9.]+)/\">',ff)
newurl=url+mlist[-1]+"/RIBS/"

f=urllib.urlopen("http://"+newurl)
ff=f.read()
f.close()
dlist=re.findall(">(rib.[0-9]{8}.[0-9]{4}.bz2)<",ff)
finalurl=newurl+dlist[-1]
q=urllib.urlretrieve("http://"+finalurl,path+dlist[-1])
os.popen("ln -sf %s %s"%(path+dlist[-1],path+"rib.latest"))
